<template>
	<view class="content-box" :class="!hasToken?'noLogin':''">
		<view class="isLogin">
			<text>denglu</text>
		</view>
	</view>
	<view class="tooltipMsg" v-show="!hasToken">
		<text>请登陆后获取更多内容</text>
		<button type="default" class="simple-button" style="margin-top: 30rpx;" @click="loginFn">登录</button>
	</view>
</template>

<script setup>
	import {
		onBeforeMount,
		ref
	} from "vue";

	import {
		onReady,
		onShow
	} from "@dcloudio/uni-app";
	import utils from "/pages/utils/index.js"
	import {
		checkLogin
	} from "@/pages/components/checkLogin.js";

	let hasToken = ref(false)
	let hasDone = ref(false)
	onReady(() => {
		checkLogin();
	});
	onShow(() => {
		if (uni.getStorageSync("uni_id_token")) {
			hasToken.value = true
			if (!hasDone.value) {
				let id = uni.getStorageSync("uni-id-pages-userInfo")._id
				utils.requestCloudDB("get", {
					collection: "uni-id-users",
					whereParam: {
						_id: id
					},
					limitParam: 1,
					filedParam: "username"
				}, (res) => {
					if (res.data) {
						let data = res.data
						hasDone.value = true
					}
				})
			}

		} else {
			hasToken.value = false
		}
	})
	const loginFn = () => {
		checkLogin();
	}
</script>

<style scoped>
	.noLogin {
		filter: blur(5rpx);
	}

	.tooltipMsg {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		font-size: 34rpx;
		font-weight: bold;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
</style>